unit Log;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, JvXPCheckCtrls, Mask, JvExMask, JvToolEdit,
  JvExControls, JvComponent, JvXPCore, JvXPButtons, DB, ZAbstractRODataset,
  ZAbstractDataset, ZDataset, DBCtrls;

type
  TFormLog = class(TForm)
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Panel1: TPanel;
    Memo1: TMemo;
    Memo2: TMemo;
    JvXPButton3: TJvXPButton;
    Label1: TLabel;
    DataIni: TJvDateEdit;
    Label2: TLabel;
    DataFim: TJvDateEdit;
    JvXPCheckboxIns: TJvXPCheckbox;
    JvXPCheckboxAlt: TJvXPCheckbox;
    JvXPCheckboxEx: TJvXPCheckbox;
    EditTexto: TEdit;
    Label3: TLabel;
    ZQuery1: TZQuery;
    ZQuery1NOME: TStringField;
    ZQuery1DATA: TDateTimeField;
    ZQuery1ARQUIVO: TStringField;
    ZQuery1TIPO: TStringField;
    ZQuery1OBS: TBlobField;
    DBNavigator1: TDBNavigator;
    DataSource1: TDataSource;
    Panel2: TPanel;
    Label4: TLabel;
    EditUsuario: TEdit;
    Label5: TLabel;
    Label6: TLabel;
    lblUsuario: TLabel;
    lblTipo: TLabel;
    procedure JvXPButton3Click(Sender: TObject);
    procedure DataSource1DataChange(Sender: TObject; Field: TField);
    procedure FormShow(Sender: TObject);
    procedure JvXPCheckboxExClick(Sender: TObject);
    procedure JvXPCheckboxAltClick(Sender: TObject);
    procedure JvXPCheckboxInsClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    SqlOld : TStrings;
    procedure SetaMemo(Separador : String);

  public
    { Public declarations }
  end;

var
  FormLog: TFormLog;

implementation

uses DM, Geral;

{$R *.dfm}

procedure TFormLog.JvXPButton3Click(Sender: TObject);
begin
    with ZQuery1 do
    begin
        Close;
        sql.Clear;
        SQL.AddStrings(SqlOld);
        ParamByName('pdatai').AsDateTime := DataIni.Date;
        ParamByName('pdataf').AsDateTime := DataFim.Date;
        if JvXPCheckboxIns.Checked then
            ParamByName('PTIPOR').AsString := 'I'
        else
        if JvXPCheckboxAlt.Checked then
            ParamByName('PTIPOR').AsString := 'A'
        else
        if JvXPCheckboxEx.Checked then
            ParamByName('PTIPOR').AsString := 'R';
        if EditUsuario.Text <> '' then
            SQL.Add('and nome = '+ ChrToStr(EditUsuario.Text,39));
        if EditTexto.Text <> '' then
            SQL.Add('and obs like '+ ChrToStr('%'+EditTexto.Text+'%',39));
        open;
    end;
end;


procedure TFormLog.SetaMemo(Separador : String);
var I: Integer;
    Vetor : Vet;
begin
    Memo1.Clear;
    Memo2.Clear;
    with ZQuery1 do
    begin
        Vetor := StrToVet(ZQuery1.FieldByname('obs').AsString, Separador );
        if Separador = 'Antigo:' then
        begin
            for I := 1 to ContaStr(ZQuery1.FieldByname('obs').AsString, Separador) do
            begin
                Memo1.Lines.Add(copy(vetor[I], 7 , pos('Novo:', vetor[I])-8));
                Memo2.Lines.Add(copy(vetor[I], pos('Novo:', vetor[I])+6, length(vetor[i])-pos('Antigo:', vetor[I])-8));
            end;
        end
        else
        begin
            for I := 1 to ContaStr(ZQuery1.FieldByname('obs').AsString, Separador) do
            begin
                Memo1.Lines.Add(vetor[I]);
            end;
        end;
    end;
end;

procedure TFormLog.DataSource1DataChange(Sender: TObject; Field: TField);
begin
    if JvXPCheckboxAlt.Checked then
        SetaMemo( 'Antigo:')
    else
        SetaMemo( #13);
    with ZQuery1 do
    begin
        lblUsuario.Caption := FieldByName('NOME').AsString;
        lblTipo.Caption := FieldByName('TIPO').AsString;
    end;
end;

procedure TFormLog.FormShow(Sender: TObject);
begin
    lblUsuario.Caption := '';
    lblTipo.Caption := '';
    SqlOld := TStringList.Create;
    SqlOld.AddStrings(ZQuery1.SQL);
end;

procedure TFormLog.JvXPCheckboxExClick(Sender: TObject);
begin
    JvXPCheckboxAlt.Checked := False;
    JvXPCheckboxIns.Checked := False;
end;

procedure TFormLog.JvXPCheckboxAltClick(Sender: TObject);
begin
    JvXPCheckboxEx.Checked := False;
    JvXPCheckboxIns.Checked := False;
end;

procedure TFormLog.JvXPCheckboxInsClick(Sender: TObject);
begin
    JvXPCheckboxAlt.Checked := False;
    JvXPCheckboxEx.Checked := False;
end;

procedure TFormLog.FormClose(Sender: TObject; var Action: TCloseAction);
begin
    SqlOld.Free;
end;

end.
